package org.softmed.rest.editor.tabs;

import java.awt.Color;

import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.ScrollPaneConstants;

import net.miginfocom.swing.MigLayout;

import org.softmed.rest.editor.EditorUtil;
import org.softmed.rest.editor.commons.SwingUtil;
import org.softmed.swing.IconManager;

public class CloseableTabbedPane extends JTabbedPane {

	public CloseableTabbedPane() {

		// SwingUtil.setSize(this, 580, 700);
		// SwingUtil.setSize(tabbedPane, 580, 700);
		// setBackground(Color.BLUE);
		// add(tabbedPane);
		// addTab("wazza", new JPanel());

		// setTabComponentAt(0, panel);
	}

	public void addCloseableTab(String label, JComponent content) {
		JPanel panel = new JPanel();
		MigLayout layout = new MigLayout("left, insets "
				+ EditorUtil.smallestInsets + ", gap 0");
		panel.setLayout(layout);

		panel.add(content);
		JScrollPane scroll = new JScrollPane(panel);
		scroll
				.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
		addTab(label, scroll);
		int index = getTabCount();
		setTabComponentAt(index - 1, new CloseTabHeader(label, this));
		setSelectedIndex(index - 1);

	}
}
